<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>领取中心</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection"/>
    <link href="/css/preview.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" href="/css/icon.css">
    <link href="https://cdn.bootcss.com/weui/1.1.2/style/weui.min.css" rel="stylesheet">
</head>
<body>
<div class="main">
    <div class="card_head">
        <img class="am-circle" src="${coupon.merchantLogo}" width="60" height="60">
    </div>
    <div class="content">
        <p>${coupon.merchantName}</p>
        <p>${coupon.name}</p>
        <button id="receiveBtn">立即领取</button>
        <#if isWechat??>
        <div class='checkbox'>
            <input type='checkbox' id='checkbox1' name='checkboox'>
            <label for='checkbox1'>是否添加到微信卡包</label>
        </div>
        </#if>

        <!-- <div class="ifaddCard">
            <input type="checkbox" name="vehicle" value="Bike">&nbsp;&nbsp;&nbsp;是否添加到微信卡包<br>
        </div> -->
        <p>有效期：<span>${coupon.startTime?date('yyyy-MM-dd')} 至 ${coupon.endTime?date('yyyy-MM-dd')}</span></p>
        <hr>
        <div class="detail-content">
            <#--<div class="detail"  style="">-->
                <#--<div><span>手机号码：</span><input id="fansPhone" type="text" placeholder="请输入手机号码" style="height:2.5rem;font-size:1rem;border:1px solid rgba(0,0,0,0.1);padding:0 10px;border-radius: 10px;"/></div>-->

                <#--&lt;#&ndash;<p class="a-link"></p>&ndash;&gt;-->
            <#--</div>-->
                <div class="detail">
                    <div class="weui-cell weui-cell_vcode" style="padding: 0;">
                        <div class="weui-cell__hd">
                            <label class="weui-label">手机号</label>
                        </div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" type="tel" placeholder="请输入手机号">
                        </div>
                    </div>
                </div>
                <hr>
        </div>
        <div class="detail-content">
            <div class="detail">
                <p>劵详情</p>
                <p class="a-link"></p>
            </div>
            <p class="detail-text-1 detail-text">
                ${coupon.description}
            </p>
        </div>
        <hr>
        <div class="detail-content">
            <div class="detail">
                <p>适用门店</p>
                <p class="a-link"></p>
            </div>
            <p class="detail-text-2 detail-text">
            <#if coupon.couponStoreList?? && coupon.couponStoreList?size == 0 >
                全门店
            </#if>
            <#if coupon.couponStoreList?? && coupon.couponStoreList?size != 0 >
                <#list coupon.couponStoreList as pl>
                ${pl.storeName} <br>
                </#list>
            </#if>
            </p>
        </div>
        <hr>
        <div class="detail-content">
            <div class="detail">
                <p>适用商品</p>
                <p class="a-link"></p>
            </div>
            <p class="detail-text-3 detail-text">
            <#if coupon.productRelationList?? && coupon.productRelationList?size == 0 >
                全商品
            </#if>
            <#if coupon.productRelationList?? && coupon.productRelationList?size != 0 >
                <#list coupon.coupon.productRelationList as pl>
                ${pl.productName}<br>
                </#list>
            </#if>
            </p>
        </div>
        <#--<div  class="detail">-->
            <#--<div>-->
                <#--<p>眼管家</p>-->
                <#--<p>江南西465656号</p>-->
            <#--</div>-->
            <#--<div class="aui-palace-grid-icon" onclick="call()" >-->
                <#--<icon class="icon phone" style="color: #e65737;font-size:24px"></icon>-->
            <#--</div>-->
        <#--</div>-->
    </div>
</div>

<#include "inc/jssdk.ftl" >

<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<script>

    $(function() {
        var id = '${id}';
        var fansPhone = $('#fansPhone').val();
        if(fansPhone==null||fansPhone==""){
            // alert("请输入手机号码");
            return ;
        }
        $("#receiveBtn").on('click' , function() {
	        var box = document.getElementById("checkbox1") ? document.getElementById("checkbox1").checked : false;
            $.ajax({
                url : '/h5/coupon/receive/' + id + '?isWechat=' + box,
                method: 'get',
                success: function(res) {
                    if(res.code == 0) {
                        if(res.data && res.data.cardSign) {
                        	var detailId = res.data.detail.id;
                            wx.addCard({
                                cardList: res.data.cardSign,
                                success: function (res) {
                                    changeSyncWechatStatus(detailId);
                                    window.location.href = '/h5/index'
                                },
                                cancel: function (res) {
                                    window.location.href = '/h5/index'
                                }
                            });
                        }else {
                            window.location.href = '/h5/index'
                        }
                    }else {
                        alert(res.msg)
                    }
                }
            })

        })

        $('.detail-content').on('click', function() {
            if($(this).find('p.active').length > 0) {
                $(this).find('p.detail-text').removeClass('active')
                $(this).find('p.a-link').removeClass('act')
            }else {
                $(this).find('p.detail-text').addClass('active')
                $(this).find('p.a-link').addClass('act')
            }

        })
        
        //更改卡券同步微信卡包状态
        function changeSyncWechatStatus(id){
            $.ajax({
                url: '/h5/coupon/sync/wechat/' +id,
                method: 'get',
                success: function(res) {
                    if(res.code == 0) {
                        window.location.href = '/h5/index'
                    }else {
                        alert(res.msg)
                    }
                }
            })
        }
	        
    })
//    function showDetailText(txt){
//        var Alink = document.querySelector('.a-link')
//        var detailText = document.querySelector('.detail-text')
//        $('.detail-text').removeClass('active')
//        if(Alink.className == 'a-link'){
//            Alink.className = 'a-link act'
//            detailText.className = 'detail-text active'
//
//            // detailText.style.height ='40px'
//        }else{
//            Alink.className = 'a-link'
//            detailText.className = 'detail-text'
//            // detailText.style.height ='0'
//        }
//    }
</script>
</body>
</html>